/*jslint browser: true, cap: false, passfail: false, undef: false, white: false */
/*global SONGHAY YAHOO */

(function(){

    SONGHAY.ui.Client =
    {
        ajax: SONGHAY.ui.Ajax,
        application: null,
        applicationName: 'GenericWebEditor',
        applicationTitle: 'GenericWeb Editor',

        getUri: function()
        {
            var vPageName = (arguments.length > 0) ? arguments[0] : 'default';
            var vPage = (arguments.length > 1) ? arguments[1] : '';
            var vId = (arguments.length > 2) ? arguments[2] : '';

            switch(vPageName)
            {
                case 'default':
                    vPage = 'ServerHandler.ashx?' +
                        'cnn=' + self.settings.DataConnectionId.value +
                        '&cmd=' + vPage +
                        '&id=' + vId +
                        '&salt=' + new Date().getTime();
                    break;

                case '_other?':
                    break;
            }

            var vUri = './' + vPage;

            return vUri;
        },

        initialize: function()
        {
            //Get a reference to the Client Application (on window.load):
            self.application = self.ui[self.applicationName];

            //Plug this Client into Ajax:
            self.ajax.client = self;

            if (self.root.canEnhance())
            {
                if (document.title) { document.title = self.applicationTitle; }

                if (self.dataForm.loadAppSettings())
                {
                    self.application.buildDisplay('initialize');
                }
            }
        },

        /**
        * The root container of this Client.
        * @property root
        * @type object
        */
        root: SONGHAY,

        settings: null,

        /**
        * The user interface branch of the root container.
        * @property ui
        * @type object
        */
        ui: SONGHAY.ui
    };

    //Module-level "this":
    var self = SONGHAY.ui.Client;

    YAHOO.util.Event.addListener(window, 'load', self.initialize);

})();
